package com.nbjtjc.safe.util;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.nbjtjc.safe.model.sys.SysDept;
import com.nbjtjc.safe.model.sys.SysUser;
import org.apache.shiro.SecurityUtils;

import javax.print.DocFlavor;

/**
 * @auther guqianbin
 * @date 2018/3/26 17:57
 **/
public class MyShiroUtils {

    public static Integer getSessionUserId(){
        SysUser sysUser= (SysUser) SecurityUtils.getSubject().getSession().getAttribute("user");
        if(ObjectUtil.isNull(sysUser)){
            return 0;
        }else {
            return sysUser.getUserId();
        }
    }
    public static SysUser getSessionUser(){
        SysUser sysUser= (SysUser) SecurityUtils.getSubject().getSession().getAttribute("user");
        return sysUser;
    }
    public static Integer getDeptId(){
        SysUser sysUser= (SysUser) SecurityUtils.getSubject().getSession().getAttribute("user");
        if(ObjectUtil.isNull(sysUser)){
            return 0;
        }else {
            return sysUser.getDeptId().intValue();
        }
    }
    public static Integer getCompanyId(){
        SysUser sysUser= (SysUser) SecurityUtils.getSubject().getSession().getAttribute("user");
        if(ObjectUtil.isNull(sysUser)){
            return 0;
        }else {
            return sysUser.getCompanyId().intValue();
        }
    }
    public static Integer getPostId(){
        SysUser sysUser= (SysUser) SecurityUtils.getSubject().getSession().getAttribute("user");
        if(CollectionUtil.isEmpty(sysUser.getPosts())){
            return 0;
        }else {
            return sysUser.getPosts().get(0).getPostId();
        }
    }
    public static String getSessionUserName(){
        SysUser sysUser= (SysUser) SecurityUtils.getSubject().getSession().getAttribute("user");
        if(ObjectUtil.isNull(sysUser)){
            return "";
        }else {
            return sysUser.getUsername();
        }
    }
}
